package com.controller.Front;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.common.ajax.AjaxRes;
import com.common.mybatis.Page;
import com.controller.base.BaseController;
import com.entity.Attachment;
import com.entity.NewsInformation;
import com.service.AttachmentService;
import com.service.NewsInformationService;
/**
 * 新闻资讯控制器
 * @author Administrator
 *
 */
@Controller
@RequestMapping("/FrontNews/")
public class FrontNewsController  extends BaseController<Object>{
	
	//新闻详情
	@Autowired
	private NewsInformationService NewsInforServ;
	
	//附件
	@Autowired
	private AttachmentService attServ;
	
	
	@RequestMapping("/ShowNews")
	@ResponseBody
	public AjaxRes ShowNews(NewsInformation n,Page<NewsInformation> page)throws Exception{
		AjaxRes res=new AjaxRes();
		Page<NewsInformation> newPages =NewsInforServ.findByPageByNewid(new NewsInformation(), page,n.getNewsId());
		if(newPages.getResults()==null){
			res.setResMsg("数据查询为0");
		}else{
			res.setSucceed(newPages, "数据获取成功");
		}
		return res;
	}
	
	
	@RequestMapping("/newdetails")
	public ModelAndView newdetails(NewsInformation n){
		ModelAndView mv=new ModelAndView();
		List<NewsInformation> Newslist=NewsInforServ.find(n);
		try {
			Attachment att=new Attachment();
			att.setAssociatedName("newsInformation");
			att.setAssociatedId(n.getNewsInformationId());
			List<Attachment> attList=attServ.find(att);
			mv.addObject("attList", attList);
		} catch (Exception e) {
			// TODO: handle exception
		}
		mv.addObject("Newslist", Newslist.get(0));
		mv.setViewName("FrontEnd/newdetails");
		return mv;
	}
}
